package com.jsy.mini12306.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsy.mini12306.common.entity.Passenger;
import com.jsy.mini12306.user.service.PassengerService;
import com.jsy.mini12306.user.vo.PassengerVO;
import com.jsy.mini12306.user.mapper.PassengerMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

import java.util.Objects;


/**
 * 乘客表(Passenger)表服务实现类
 *
 * @author: SongyangJi
 * @since: 2021-09-01 00:43:43
 * @description:
 */


@Slf4j
@Service("passengerService")
public class PassengerServiceImpl extends ServiceImpl<PassengerMapper, Passenger> implements PassengerService {

    @Resource
    private PassengerMapper passengerMapper;



    @Override
    public Passenger login(PassengerVO passengerVO) {
        if (passengerVO.getId() == null) return null;
        String id = passengerVO.getId();
        String password = passengerVO.getPwd();

        Passenger realPassengerByUserName = passengerMapper.selectOne(new QueryWrapper<Passenger>()
                .eq("user_name",id));
        if (realPassengerByUserName != null && Objects.equals(realPassengerByUserName.getPassword(), password)) {
            System.out.println(realPassengerByUserName);
            return realPassengerByUserName;
        }

        Passenger realPassengerByEmail = passengerMapper.selectOne(new QueryWrapper<Passenger>()
                .eq("email", id));
        if (realPassengerByEmail != null && Objects.equals(realPassengerByEmail.getPassword(), password)) {
            return realPassengerByEmail;
        }
        return null;
    }


}
